

<template>
  <div>
    <el-button class="butB_Sel" @click="printBtn()">打印</el-button>
    <div class="app-container" id="printcons">
      <div
        v-for="(item2, it) in drug2"
        :key="it"
        :style="
          it == 0
            ? 'width:800px;padding:0px 40px;paddingTop:40px;height:1050px;font-size:20px'
            : style2
        "
      >
        <el-row>
          <el-col :span="20" v-if="cfdata.order_type!=2">
            <h1 style="text-align: center" >{{ his_name }}处方笺</h1>
          </el-col>
           <el-col :span="20" v-else>
             <h1 style="text-align: center" >{{ his_name }}</h1>
             <h3 style="text-align: center" >诊疗项目申请单</h3>
          </el-col>
          <el-col :span="4">
            <h1 style="text-align: center">普通</h1>
          </el-col>
        </el-row>
        <div style="margin: 10px 0px">
          <el-row>
            <el-col :span="6"> 科室:{{ cfdata.dept_info.name }} </el-col>
            <el-col :span="10"> 费用:{{ fee_category_name }} </el-col>
            <el-col :span="8"> 时间:{{ cfdata.created_at }} </el-col>
          </el-row>
        </div>
        <div
          style="
            height: 100px;

            border-top: 2px solid;
            border-bottom: 2px solid;
            box-sizing: border-box;
            margin: 10px 0px;
          "
        >
          <el-row>
            <el-col :span="6" style="line-height: 50px">
              姓名:{{ cfdata.member.name }}
            </el-col>
            <el-col :span="6" style="line-height: 50px">
              性别:{{
                cfdata.member.gender == 1
                  ? "男"
                  : cfdata.member.gender == 2
                  ? "女"
                  : "其他"
              }}
            </el-col>
            <el-col :span="4" style="line-height: 50px">
              年龄:{{ cfdata.member.age }}岁
            </el-col>

            <el-col :span="8" style="line-height: 50px">
              门诊号:{{ cfdata.patient_no }}
            </el-col>
            <el-col :span="24" style="line-height: 50px">
              <div class="juzhong">住址: {{ cfdata.member.address }}</div>
            </el-col>
          </el-row>
        </div>

        <div
          style="
            min-height: 50px;
            line-height: 50px;

            border-bottom: 2px solid;
            box-sizing: border-box;
            margin: 5px 0px;
          "
        >
          <el-row>
            <el-col :span="4"> 临床诊断: </el-col>

            {{
              cfdata.medical_record.diagnosis.length != 0
                ? cfdata.medical_record.diagnosis[0].name
                : ""
            }}
          </el-row>
        </div>
        <!-- <div style="text-align: center;border-bottom: 1px solid;">
        <el-row>
            <el-col :span="1">
                &nbsp;
            </el-col>
            <el-col :span="7">
                药品名称
            </el-col>
              <el-col :span="4">
                药品规格
            </el-col>
              <el-col :span="4">
                一次剂量
            </el-col>
              <el-col :span="4">
                数量
            </el-col>
               <el-col :span="4">
                单价
            </el-col>
        </el-row>
    </div> -->
        <div style="height: 600px">
          <el-col :span="1">
            <h2 style="margin: 0px">R:</h2>
          </el-col>
          <el-col :span="22">
            <el-row v-for="(item, index) in item2" :key="index">
              <el-col :span="10" style="margin-top: 40px">
                {{ item.drug.name }}
              </el-col>
              <el-col :span="7" style="margin-top: 40px">
                {{ item.drug.specification }}
              </el-col>
              <el-col :span="2" style="margin-top: 40px"> &#12288; </el-col>
              <el-col :span="3" style="margin-top: 40px">
                {{ item.num }} {{ item.drug.base_unit }}
              </el-col>
              <el-col :span="2" style="margin-top: 40px">
                {{ item.price }}
              </el-col>
              <el-col :span="24" :offset="2" style="margin-top: 20px">
                用法 : {{ item.dose }}{{ item.dose_unit }} &#12288;
                {{ item.drug.usage }} &#12288; {{ item.drug.each_dos }}
              </el-col>
            </el-row>
          </el-col>
        </div>
        备注: {{ cfdata.remark }}
        <div
          style="
            height: 35px;
            line-height: 35px;
            border-top: 2px solid;
            border-bottom: 2px solid;
            box-sizing: border-box;
          "
        >
          <el-row>
            <el-col :span="8" style="padding-left: 5px">
              医师:{{ cfdata.doctor.real_name }}
            </el-col>
            <el-col
              :span="8"
              style="
                padding-left: 5px;
                border-left: 2px solid;
                border-right: 2px solid;
              "
            >
              药价:{{ cfdata.should_amount }}
            </el-col>
            <el-col :span="8" style="padding-left: 5px"> 其他: </el-col>
          </el-row>
        </div>
        <div
          style="
            height: 35px;
            line-height: 35px;

            border-bottom: 2px solid;
            box-sizing: border-box;
          "
        >
          <el-row>
            <el-col :span="8" style="padding-left: 5px"> 调剂: </el-col>

            <el-col
              :span="8"
              style="
                padding-left: 5px;
                border-left: 2px solid;
                border-right: 2px solid;
              "
            >
              核对、发药:
            </el-col>
            <el-col :span="8" style="padding-left: 5px"> 取药: </el-col>
          </el-row>
        </div>
        <div>备注:该处方及申请单仅限当日当次使用:谢谢配合</div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  // props:['cfdata'],
  data() {
    return {
      tabeldata: {},
      sourcelist: [],
      style2: {
        width: "800px",
        padding: "0px 40px",
        marginTop: "0",
        height: "1150px",
        fontSize: "20px",
        paddingTop: "40px",
      },
      drug2: [],
      fee_category_name: "",
      dayin: false,
      his_name: process.env.VUE_APP_HOSPITAL_API2,
      cfdata: {},
      dept_info_name: "",
    };
  },

  mounted() {
    this.drug2 = [];
    this.cfdata = JSON.parse(this.$route.query.cfdata);
    //console.log("cfdata",this.cfdata.order_type)
    this.dept_info_name =
      this.cfdata.dept_info == undefined
        ? this.cfdata.dept_name
        : this.cfdata.dept_info.name;

    console.log(this.$route.query.cfdata);
    this.his_name = process.env.VUE_APP_HOSPITAL_API2;
    var arr = this.cfdata.drug;
    if (this.cfdata.drug.length > 5) {
      for (let i = 0; i < Math.ceil(arr.length / 5); i++) {
        this.drug2.push(arr.slice(i * 5, 5 * (i + 1)));
      }
      console.log(this.drug2);
    } else {
      this.drug2.push(arr);
    }
    this.fee_category_name = this.drug2[0][0].drug.fee_category.name;
  },
  //  watch: {

  //   cfdata(n) {
  //     this.drug2=[]
  // 	console.log(n.drug,'进入')
  //     var arr=n.drug
  //    if(arr.length>5){

  //     for (let i = 0; i < Math.ceil(arr.length/5); i++) {
  //    this.drug2.push(arr.slice(i*5,5*(i+1)));
  //      this.fee_category_name=this.drug2[0][0].drug.fee_category.name
  //   }

  //   }else{

  //     this.drug2.push(arr)
  //   }
  //      console.log(this.drug2,'1111111')
  //      this.fee_category_name=this.drug2[0][0].drug.fee_category.name
  // },

  //   },

  methods: {
    getindex() {
      getdictIndex({ group_id: "40" }).then((res) => {
        let data = res.data;
        data.forEach((item, key) => {
          if (item.id == 40) {
            this.sourcelist = item.items;
          }
        });
      });
    },
    getpint() {
      this["_API"].getPrintReport({ id: this.id }).then((res) => {
        if (res.code == 200) {
          this.tabeldata = res.data;
          this.tabeldata.source = this.mapxing(this.tabeldata.source);
        }
      });
    },

    mapxing(num) {
      var art = "";
      this.sourcelist.map(function (value, i, array) {
        if (value.id == num) {
          art = value.name;
        }
      });
      console.log(art);
      return art;
    },
    printBtn(e) {
      this.dayin = true;

      setTimeout(() => {
        this.dayinfun();
      }, 200);
    },
    dayinfun() {
      this.remove_ie_header_and_footer();
      let subOutputRankPrint = document.getElementById("printcons");
      console.log(subOutputRankPrint.innerHTML);
      let newContent = subOutputRankPrint.innerHTML;
      let oldContent = document.body.innerHTML;
      document.body.innerHTML = newContent;
      window.print();
      // window.location.reload();
      window.open("", "_self").close(), (document.body.innerHTML = oldContent);
      return false;
    },
    //去掉页眉和页脚
    remove_ie_header_and_footer() {
      var hkey_path;
      hkey_path =
        "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
      try {
        var RegWsh = new ActiveXObject("WScript.Shell");
        RegWsh.RegWrite(hkey_path + "header", "");
        RegWsh.RegWrite(hkey_path + "footer", "");
      } catch (e) {}
    },
  },
};
</script>
<style media="print">
@page {
  size: auto; /* auto is the initial value */
  margin: 0mm; /* this affects the margin in the printer settings */
}
@media print {
}
body {
  -webkit-print-color-adjust: exact;
}
#printcons {
  margin: auto;
  box-sizing: border-box;
}
</style>
<style lang='scss' scoped>
</style>